﻿using MCPlatform.MotionLib.Base.Models;
using MCPlatform.MotionLib.Base;
using MCPlatform.UI.Controls.Models;
using Panuon.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace MCPlatform.Models.Motions
{
    public class IOModel : NotifyPropertyChangedBase
    {
        #region Properties
        public IIO? IOEntity
        {
            get => _IOEntity;
            set { Set(ref _IOEntity, value); Initial(); }
        }
        private IIO? _IOEntity;
        public IODataModel IODataModel { get => _IODataModel; set => Set(ref _IODataModel, value); }
        private IODataModel _IODataModel = new IODataModel();

        public IOParaModel IOParaModel { get => _IOParaModel; set => Set(ref _IOParaModel, value); }
        private IOParaModel _IOParaModel = new IOParaModel();

        #endregion

        #region Methods

        Timer timer;
        public void StartMappingEntityToModel()
        {
            if (IOEntity is null)
            {
                return;
            }

            timer.Start();


        }


        public void StopMappingEntityToModel()
        {

            timer.Stop();


        }

        #endregion

        #region CTOR

        public IOModel()
        {
            timer = new Timer(200);
            timer.Elapsed += Timer_Elapsed;


        }


        private void Timer_Elapsed(object? sender, ElapsedEventArgs e)
        {

            IOParaModel.IOEntity = IOEntity;
            IODataModel.IOEntity = IOEntity;

            IODataModel.Mapping();


        }

        public void Initial()
        {
            IOParaModel.IOEntity = IOEntity;
            IODataModel.IOEntity = IOEntity;
        }
        #endregion
    }
}
